home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Set-merging algorithm?
- Date: 15 Apr 1996 08:00:18 -0700
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Distribution: inet
- Message-ID: <4ktoa2INNp6s@keats.ugrad.cs.ubc.ca>
- References: <m1a91fx7jh9.fsf@gamma.hut.fi>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <m1a91fx7jh9.fsf@gamma.hut.fi>,
- Petri Hakola <Petri.Hakola@hut.fi> wrote:
- >
- > 'allo,
- >
- > Is there any sophisticated algorithm for merging and building
- > combinations from sets.
- >
- > Like this:
- > I have {a, b, c} + {d e} + {f} and I need to form all possible
- > combinations. The amount of combs. is (of course) 3*2*1 = 6,
- > and the groups are as follows:
- >
- > {a d f} + {a e f} + {b d f} + {b e f} + {c d f} + {c e f}
- >
- > (i.e. only one member per set is 'allowed' in one group
- > (superset?))
-
- This is called a Cartesian product (well, not quite). Your notation is
- different. A Cartesian product is a binary operation that forms all possible
- ordered pairs from the elements of two sets:
-
- ( {a, b, c} X { d, e } ) X { f }
-
- = { <a,d>, <a,e>, <b,d>, <b, e>, <c, d>, <c, e> } X { f }
-
- = { <<a,d>,f>, <<a,e>,f>, <<b,d>,f>, <<b,e>,f>, <<c,d>,f>, <<c,e>,f> }
-
-
- The difference is that the results are nested, ordered tuples.
-
- > If there are more than a couple of sets, the amount of time
- > required to build all combinations is quite long, so I'd like
- > to know is there a better way to build these than
- > BruteForce.
-
- I can't think of a way. The fact is that if you want to actually construct the
- product, you have to go through all the combinations, because you have to add
- that many elements to the resulting set!
-
- An alternative would be to represent the sets as trees. In other words, don't
- perform the combination at all, but represent them as a compound expression
- that you dynamically evaluate (when testing for set membership), and update
- (when inserting new items).
-
-
- For instance, if I know that set S is the combination of A and B (a Cartesian
- product, for the sake of simplicity), <x,y> is in S if and only if x is in A,
- and y is in B. This check is faster than searching through the entire
- space looking for <x,y>. Such a search is only needed when the search space
- does not trivially correspond to all possible combinations. In such a case,
- some sort of sparse matrix representation would be used anyway.
-
- --
- I'm not really a jerk, but I play one on Usenet.
-